import re
import download_webpage as down_page

def link_crwaler(seed_url, link_regex):
    '''

    '''
    crwal_queue = [seed_url]
    while crwal_queue:
        url = crwal_queue.pop()
        html = down_page.download(url)

        for link in get_links(html):
            if re.match(link_regex, link):
                crwal_queue.append(link)


def get_links(html):
    """
    """
    webpage_regex = re.compile('<a[^>]+href=["\'](.*?)["\']',re.IGNORECASE)
    return webpage_regex.findall(html)


link_crwaler('http://example.webcsraping.com', '/(index|view)')